import math


class LineGeometry:

    def abscurve(self, p1, p2, p3):
        (x1,y1), (x2,y2), (x3,y3) = p1, p2, p3
        a, b, c = self.line2d_in_general_form(p1, p3)
        if a == b == 0: return 0
        return abs((a*x2+b*y2+c)/math.sqrt(a**2+b**2))

    def line2d_in_general_form(self, p1, p2):
        """Ax+By+C=0"""
        (x1,y1), (x2,y2) = p1, p2
        # multiply eq.1 by x2, and eq.2 by x1
        """Ax1x2+By1x2+Cx2=0
           Ax1x2+By2x1+Cx1=0"""
        # subtract
        """B(y1x2-y2x1)+C(x2-x1)=0"""
        if y1*x2 - y2*x1 == 0:
            return y2, -x2, 0
        c = 1.0
        b = -c*(x2-x1) / (y1*x2 - y2*x1)
        # multiply eq.1 by y2, and eq.2 by y1
        """Ax1y2+By1y2+Cy2=0
           Ax2y1+By1y2+Cy1=0"""
        # subtract
        """A(x1y2-x2y1)+C(y2-y1)=0"""
        a = -c*(y2-y1) / (x1*y2 - x2*y1)
        return a, b, c

